#!/usr/bin/env node

const http = require('http'),
      log = console.log,
      url = require('url'),
      cheerio = require('cheerio'),
      qs = require('querystring'),
      fs = require('fs'),
      addr = 'https://maoyan.com/films?showType=3';

let items = [];

function genpage(){
    let html = fs.readFileSync('./index.html').toString('utf8');
    return html;
}

http.createServer((req,res)=>{
  if(req.url !=='/'){
    res.statusCode = 404;
    res.setHeader('Content-Type','text/html');
    res.end('<h1>Not Found!</h1>');
    return;                  
  }
  let data = '';
  req.on('data',chunck =>data+=chunck);
  req.on('end',()=>{
    res.writeHead(200,{
      'Content-Type':'text/html',
      'Content-length':Buffer.byteLength(genpage())        
    });
    res.end(genpage());          
  });
}).listen(8081);

